import 'package:coins/common/DeviceUtils.dart';
import 'package:coins/constant/Theme.dart';
import 'package:coins/maintab/homepage/ArticleListPage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'dart:ui';

class ArticlesPage extends StatefulWidget {
  var data;

  ArticlesPage(this.data);

  @override
  State<StatefulWidget> createState() {
    return new ArticlesPageState();
  }
}

class ArticlesPageState extends State<ArticlesPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;

  List<Tab> tabs = new List();

  List<dynamic> list;

  @override
  void initState() {
    super.initState();

    list = widget.data['category'];

    for (var value in list) {
      tabs.add(new Tab(text: value['title']));
    }

    _tabController = new TabController(length: list.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    print("========statusBarHeight=" + DeviceUtils.statusBarHeight(context).toString());
    print("==========screenWidth=" + DeviceUtils.screenWidth(context).toString());
    print("==========screenHeight=" + DeviceUtils.screenHeight(context).toString());

    timeDilation = 1.0;
    return new Scaffold(
        appBar: PreferredSize(
            child: AppBar(
              title: new Text("首页"),
              //primary: true,
              elevation: 0,
              //textTheme:ThemeUtil.titleTheme,
              //centerTitle:true,
            ),
            preferredSize: Size.fromHeight(0)),
        body: new DefaultTabController(
          length: list.length,
          child: new Scaffold(
              appBar: new TabBar(
                isScrollable: true,
                controller: _tabController,
                labelColor: Theme.of(context).accentColor,
                unselectedLabelColor: Colors.black,
                indicatorColor: Theme.of(context).accentColor,
                tabs: tabs,
              ),
              body: new TabBarView(
                controller: _tabController,
                //children: <Widget>[],
                children: list.map((dynamic itemData) {
                  return new ArticleListPage(itemData['route_sn'].toString());
                }).toList(),
              )),
        ));
  }
}
